<?php
namespace jy_edu;
defined('BY_JYA') or exit('error');
/*
	课程
*/
class lesson extends \plugin{
	/*
		获取最近课程
	*/
	public function get_lessonlast($body=array()){
		$class=pdo_get('jy_edu_class',array('id'=>$body['classid']));
		$class['class_lesson']=json_decode($class['class_lesson'],true);
		$weekid=date("w");
		$ymd=date('Y-m-d',TIMESTAMP);
		paixu($class['class_lesson'],'xinqi','asc');
		foreach($class['class_lesson'] as $item){
			if($item['xinqi']==0 || $item['xinqi']>=$weekid){
					$item['shijian']=strtotime($ymd.' '.$item['time']['start']);
					if($item['shijian']>TIMESTAMP){
						$lessontitle=pdo_getcolumn('jy_edu_lesson',array('id'=>$item['lessonid']),'title');
						$lessontime=$this->week_days[$item['xinqi']].'~'.$item['time']['start'];
						break;
					}
			}
		}
		if($lessontitle){
			$lessonlast='《'.$lessontitle.'》'.$lessontime;
		}else{
			$lessonlast='本周没有任何课程';
		}
		return $lessonlast;
	}
	public function get_days($classid,$days=7){
		$class=pdo_get('jy_edu_class',array('uniacid'=>$_SESSION['uniacid'],'id'=>$classid));
		//日期
		$data=array();
		$weekarray=array("日","一","二","三","四","五","六"); //先定义一个数组
		$days=$days>0?$days:7;
		for($i=0;$i<$days;$i++){
			$data[]=array(
				'ymd'=>date("Y-m-d",strtotime("+".$i." day")),
				'riqi'=>date("m-d",strtotime("+".$i." day")),
				'xinq'=>"星期".$weekarray[date("w",strtotime(date("Y-m-d",strtotime("+".$i." day"))))],
			);
		}
		return $data;
	}
}